#include <iostream>

template<typename T>

void Swap(T &a,T &b)
{
    T temp = a;
    a = b;
    b = temp;
}
template<typename T>
void Sort(T *a,int size)
{
    for(int i = 0;i < size;i++)
    {
        for(int j = 0;j < size - i - 1;j++)
        {
            if(a[j] > a[j+1])
                Swap(a[j],a[j+1]);//模板函数中用模板函数
        }
    }
}

struct Student
{
    int id;
    std::string name;
    bool operator>(const Student& s)
    {
        return id > s.id;
    }
};

std::ostream &operator<<(std::ostream &os,const Student& s)
{
    os<<s.id<<" "<<s.name<<"\n";
    return os;
}

//特化：模板的具体化
//显示声明模板的数据类型
template<>
void Swap<Student>(Student& a,Student &b)
{
    std::cout<<"特化函数\n";
    std::string temp = a.name;
    a.name = b.name;
    b.name = temp;
}

int main()
{
    // Student a[3] = 
    // {
    //     {2,"张三"},
    //     {1,"李四"},
    //     {3,"王五"}

    // };
    // Sort(a,3);
    // for(int i = 0;i < 3;i++)
    //     std::cout<<a[i];
    //std::cout<<"\n";
    Student s1 = {1,"张三"};
    Student s2 = {2,"李四"};
    Swap(s1,s2);
    std::cout<<s1;
    std::cout<<s2;

    return 0;
}